import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { BillRecordForm, BillRecordPageVO, BillRecordQuery } from "./types";
import qs from "qs";

/**
 * 获取账单实体分页列表
 *
 * @param queryParams
 */
export function getBillRecordPage(
  queryParams: BillRecordQuery
): AxiosPromise<PageResult<BillRecordPageVO[]>> {
  return request({
    url:
      "/api/v1/billRecords/page?" +
      qs.stringify(queryParams, { arrayFormat: "repeat" }),
    method: "get",
  });
}

/**
 * 获取账单实体表单详情
 *
 * @param billRecordId
 */
export function getBillRecordForm(
  billRecordId: number
): AxiosPromise<BillRecordForm> {
  return request({
    url: "/api/v1/billRecords/" + billRecordId + "/form",
    method: "get",
  });
}

/**
 * 添加账单实体
 *
 * @param data
 */
export function addBillRecord(data: any) {
  return request({
    url: "/api/v1/billRecords",
    method: "post",
    data: data,
  });
}

/**
 * 修改账单实体
 *
 * @param id
 * @param data
 */
export function updateBillRecord(id: number, data: BillRecordForm) {
  return request({
    url: "/api/v1/billRecords/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除账单实体
 *
 * @param ids
 */
export function deleteBillRecords(ids: string) {
  return request({
    url: "/api/v1/billRecords/" + ids,
    method: "delete",
  });
}
